package com.wenjiang.service.impl;

import com.wenjiang.common.dto.ChangeMenuRoleParam;
import com.wenjiang.common.dto.ChangeRoleParam;
import com.wenjiang.common.lang.Result;
import com.wenjiang.mapper.MallMenuMapper;
import com.wenjiang.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MenuServiceImpl implements MenuService {

    @Autowired
    MallMenuMapper mallMenuMapper;

    @Override
    public Object getAllMenu() {

        return Result.succ(mallMenuMapper.getAllMenu());
    }


    @Override
    public Object changeRoleMenu(ChangeMenuRoleParam changeMenuRoleParam) {

        // 先删除所有
        mallMenuMapper.deleteRoleMenu(changeMenuRoleParam.getRoleId());

        // 不为空时
        if (!changeMenuRoleParam.getMenuIds().isEmpty())
        {  //在进行添加
        mallMenuMapper.insertMenu(changeMenuRoleParam.getRoleId(), changeMenuRoleParam.getMenuIds());}

        return Result.succ("修改成功");
    }
}
